package api

import (
	"net/http"
	"nick-gingin/server"

	"github.com/gin-gonic/gin"
)

type APIError struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data" default:allowNull`
}

func Login(cxt *gin.Context) {

	jsonData := LoginParams{}

	if err := cxt.ShouldBindJSON(&jsonData); err != nil {
		cxt.JSON(http.StatusBadRequest, APIError{
			Code:    http.StatusBadRequest,
			Message: err.Error(),
		})
		return
	}

	server.Login(jsonData.Account, jsonData.Password)

	cxt.JSON(http.StatusOK, APIError{
		Code:    http.StatusOK,
		Message: "登录成功",
	})
	return
}
